<template>
  <div id="app-layout" class="layout">
    <div id="sidebar">
      <sidebar />
    </div>
    <div id="content-wrapper" class="content-wrapper">
      <div id="top-nav">
        <top-nav @childData="handleChildData"/>
      </div>
      <div v-if="showRouterView" id="main">
        <div class="inside">
          <router-view/>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Sidebar from '@/components/SideBar.vue';
import TopNav from '@/components/TopNav.vue';

export default {
  components: {
    Sidebar,
    TopNav
  },
  data() {
    return {
      showRouterView: true // 初始设置为显示router-view
    };
  },
  methods: {
    handleChildData(reloading) {
      // 根据子组件传递过来的reloading的值（这里为false）来更新showRouterView
      this.showRouterView =!reloading;
      setTimeout(() => {
        this.showRouterView =reloading;
      }, 200);
    }
  }
}
</script>

<style scoped>
.layout {
  display: flex;
  height: 100vh; /* 让整个布局占据整个视口高度 */
}

#sidebar {
  flex: 0 0 256px; /* 不增长、不缩小，宽度为256px */
}

.content-wrapper {
  display: flex;
  flex-direction: column; /* 设置为垂直布局 */
  flex-grow: 1; /* 填充剩余空间 */
}

#top-nav {
  width: 100%;
}

#main {
  flex-grow: 1; /* 主要内容区域将会填充剩余的空间 */
  padding: 20px; /* 可选：添加一些内边距 */
  background-color: #f4f6f8;
}

.inside{
  box-sizing: border-box;
  top: 10px;
  background-color: white;
  padding: 0;
  min-height: 80vh;
}
</style>
